package cs.upt.awp.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cs.upt.awp.dao.CountryDAO;
import cs.upt.awp.data.City;
import cs.upt.awp.data.Country;
import cs.upt.awp.services.CityServices;
import cs.upt.awp.services.CountryServices;
import cs.upt.awp.services.TravelNotesServices;

@Controller
@RequestMapping("/location")
public class CountryAndCityController {
	
	@Autowired
	CountryServices countryServices;
	
	@Autowired
	CityServices cityServices;
	
	@RequestMapping(value="/countries", method=RequestMethod.GET)
	public @ResponseBody List<Country> getAllCountries(){
		try {
			return countryServices.getEntityList();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ArrayList<Country>();
	}
	
	@RequestMapping(value="/cities/{code}", method=RequestMethod.GET)
	public @ResponseBody List<City> getCitiesOfCounty(@PathVariable("code") String countryCode){
		try {
			return cityServices.getCitiesOfCoury(countryCode);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ArrayList<City>();
	}

}
